import { reqGetTrade,reqSubmitOrder } from "@/api"
const state = {
    userAddressList: [],
    detailArrayList: [],
    tradeNo:'',
    data:'' //订单id
}
const actions = {
    async getTrade(context) {
        const result = await reqGetTrade()
        if (result.code === 200) {
            context.commit('GETTRADE', result.data)
        }
    },
    async submitOrder({state},data){
        const result = await reqSubmitOrder(state.tradeNo,data)
        if(result.code == 200){
            state.data = result.data
            return 'ok'
        }else{
            return Promise.reject(new Error(result.message))
        }
    }
}
const mutations = {
    GETTRADE(state, data) {
        state.userAddressList = data.userAddressList || []
        state.detailArrayList = data.detailArrayList || []
        state.tradeNo = data.tradeNo || ''
    }
}
const getters = {

}
export default {
    state,
    actions,
    mutations,
    getters
}